package com.framework.modules.sys.controller;


import com.framework.entity.sys.SysUploadExcel;
import com.framework.exception.util.RespResult;
import com.framework.page.PageUtils;
import com.framework.service.SysUploadExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("sys/excel")
public class SysUploadExcelController extends AbstractController{

    @Autowired
    private SysUploadExcelService sysUploadExcelService;

    @RequestMapping("list")
    public RespResult list(@RequestParam Map<String,Object> params){
        params.put("deptId",getDeptId());
        PageUtils page=sysUploadExcelService.queryPage(params);
        return RespResult.ok().put("page",page);

    }

    @RequestMapping("save")
    public RespResult save(@RequestBody SysUploadExcel sysUploadExcel){
        sysUploadExcelService.save(sysUploadExcel);
        return  RespResult.ok();
    }
    @RequestMapping("getById/{id}")
    public RespResult getById(@PathVariable Integer id){
        SysUploadExcel uploadExcel = sysUploadExcelService.selectById(id);
        uploadExcel.setDeptIds(uploadExcel.getDeptId().split(","));
        return RespResult.ok().put("uploadBean",uploadExcel);
    }

    @RequestMapping("modify")
    public RespResult modify(@RequestBody SysUploadExcel sysUploadExcel){
        sysUploadExcelService.modify(sysUploadExcel);
        return  RespResult.ok();
    }

    @RequestMapping("deleteById/{id}")
    public RespResult deleteById(@PathVariable Integer id){
        sysUploadExcelService.deleteById(id);
        return RespResult.ok();
    }

    @RequestMapping("downTemplate")
    public RespResult downTemplate(@RequestParam Integer templateType){
        String url=sysUploadExcelService.getTemplate(templateType,getDeptId());
        return RespResult.ok().put("url",url);
    }

}
